package com.ctshk.rpc.scenic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.scenic.dto.ScenicChargeDTO;
import com.ctshk.rpc.scenic.entity.ScenicProductCostStrategyVaildDate;
import com.ctshk.rpc.scenic.entity.ScenicProductStrategyVaildDate;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 门票成本价格加幅有效期 Mapper 接口
 * </p>
 *
 * @author wangcy
 * @since 2021-02-02
 */
public interface ScenicProductCostStrategyVaildDateMapper extends BaseMapper<ScenicProductCostStrategyVaildDate> {
    /**
     * 批量删除
     * @param productId
     * @param
     * @return
     */
    @Update("UPDATE t_scenic_product_cost_strategy_vaild_date \n" +
            "WHERE   product_id = #{product_id}")
    Integer batchDel(@Param("product_id") Long productId);

    @Select("SELECT * from t_scenic_product_cost_strategy_vaild_date \n" +
            "WHERE DATE_FORMAT(#{time},'%Y-%m-%d') >=DATE_FORMAT(time_begin,'%Y-%m-%d')  \n" +
            "and  DATE_FORMAT(#{time},'%Y-%m-%d') <= DATE_FORMAT(time_end,'%Y-%m-%d') and product_id = #{productId} limit 1" )
    ScenicProductCostStrategyVaildDate queryDetail(@Param("time") String time,@Param("productId") Long productId);

    @Select("SELECT ts.currency_id currencyId,ts.currency,ts.exchange_rate exchangeRate, ts.product_id productid " +
            ",min(tss.cost_price) costPrice  from  \n" +
            "t_scenic_product_cost_strategy_vaild_date tc \n" +
            "INNER JOIN t_scenic_product_cost_strategy ts on tc.strategy_id=ts.id\n" +
            " INNER JOIN  t_scenic_product_cost_strategy_spec_stock tss on tc.strategy_id=tss.strategy_id"+
            " where DATE_FORMAT(#{time},'%Y-%m-%d') >=DATE_FORMAT(tc.time_begin,'%Y-%m-%d')  \n" +
            " and  DATE_FORMAT(#{time},'%Y-%m-%d') <= DATE_FORMAT(tc.time_end,'%Y-%m-%d')  and  ts.product_id in (\n" +
            "${productId}" +
            ") group by ts.product_id,ts.exchange_rate,ts.currency_id,ts.currency" )
    List<ScenicChargeDTO> queryCostByProductIds(@Param("time") String time, @Param("productId") String productids);


//    @Select("SELECT ts.currency_id currencyId,ts.currency,ts.exchange_rate exchangeRate, ts.product_id productid " +
//            ",min(tss.cost_price) costPrice  from  \n" +
//            "t_scenic_product_cost_strategy_vaild_date tc \n" +
//            "INNER JOIN t_scenic_product_cost_strategy ts on tc.strategy_id=ts.id\n" +
//            " INNER JOIN  t_scenic_product_cost_strategy_spec_stock tss on tc.strategy_id=tss.strategy_id"+
//            " where strategy_id=#{strategy_id}"+
//            "group by ts.product_id,ts.exchange_rate,ts.currency_id,ts.currency" )
//    ScenicChargeDTO queryCostByProductIds(@Param("strategyId") Long strategy_id, @Param("productId") String productids);


}
